package ds.factcom.repository;


import java.util.Iterator;
import java.util.List;

import ds.factcom.domain.product.Product;
import ds.factcom.exception.NotExistDomainException;

/**
 * 
 * @author Javier De Luca, Maximiliano Herrera, Matias Samblancat
 *
 */

public class ProductRepository extends BaseRepository<Product>{
	
	private static ProductRepository instance = null;
	
	private ProductRepository(){}
	
	public static ProductRepository getInstance(){
		if (instance == null){
			instance = new ProductRepository();
		}
		return instance;
	}

		public Product findByDescription(String description) throws NotExistDomainException {
		boolean found = false;		
		for (Iterator<Product> iterator = getAllEntities().iterator(); iterator.hasNext();) {
			Product product = (Product) iterator.next();
			if(product.getDescription().equalsIgnoreCase(description)){
				found = true;
				return product;
			}
		}
		if (!found)
			throw new NotExistDomainException("Producto");
		return null;
	}
		
		public List<Product> getProductList(){
			return this.getAllEntities();
		}
		
}
